home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / f-spot-sqlite-upgrade < prev    next >
Encoding:
Text File  |  2009-04-08  |  1.2 KB  |  44 lines

  1. #!/bin/sh
  2. set -e
  3.  
  4. # This only upgrades the default database location
  5. # if you have specified a different location 
  6. DB_LOCATION=~/.gnome2/f-spot/photos.db
  7. BACKUP_LOCATION=$DB_LOCATION.backup
  8. DUMP_LOCATION=$DB_LOCATION.dump
  9. NEW_DB_LOCATION=$DB_LOCATION.new
  10.  
  11. if ! which sqlite >/dev/null 2>&1 ; then
  12.     echo "Could not find sqlite binary. Update aborted." >&2
  13.     exit 1
  14. elif ! which sqlite3 >/dev/null 2>&1 ; then
  15.     echo "Could not find sqlite3 binary. Update aborted." >&2
  16.     exit 1
  17. fi
  18.  
  19. if [ ! -f $DB_LOCATION ]; then
  20.     echo "Could not find $DB_LOCATION, nothing to update. Update aborted." >&2
  21.     exit 1
  22. fi
  23.  
  24. # make sure nothing gets in the way
  25. rm -f $BACKUP_LOCATION
  26. rm -f $DUMP_LOCATION
  27. rm -f $NEW_DB_LOCATION
  28.  
  29. if grep "^...This file contains an SQLite 2.1 database" $DB_LOCATION >/dev/null 2>&1; then
  30.     echo "Upgrading from SQLite 2.1 to SQLite3"
  31.     cp $DB_LOCATION $BACKUP_LOCATION
  32.     if sqlite $DB_LOCATION .dump > $DUMP_LOCATION &&
  33.        sqlite3 $NEW_DB_LOCATION < $DUMP_LOCATION; then
  34.         cp $NEW_DB_LOCATION $DB_LOCATION
  35.         echo "Upgrade was successful."
  36.     else
  37.         echo "Upgrade failed, putting old database back." >&2
  38.         cp $BACKUP_LOCATION $DB_LOCATION
  39.         exit 1
  40.     fi
  41. else
  42.     echo "Database is already upgraded"
  43. fi
  44.